#include <iostream>
#include <string>
#include <stack>
using namespace std;

class Teacher
{
public:
	int age;
	string name;
	void print()
	{
		cout << "age = " << age << " name = " << name << endl;
	}
};
//容器 stack 栈
void my_stack()
{
	stack<int> s;
	//入栈
	for (int i = 0; i < 10; i++)
	{
		s.push(i);
	}
	//栈的大小
	cout << "栈的大小:" << s.size() << endl;
	//出栈（先进后出）
	while (!s.empty())
	{
		int temp = s.top();//栈顶元素
		cout << temp << " ";
		s.pop();//出栈
	}

}
//存对象
void teacher_stack()
{
	stack<Teacher> s;
	Teacher t1, t2, t3;
	t1.name = "张三";
	t1.age = 34;

	t2.name = "李四";
	t2.age = 32;

	t3.name = "王五";
	t3.age = 24;

	s.push(t1);
	s.push(t2);
	s.push(t3);

	while (!(s.empty()))
	{
		s.top().print();
		s.pop();
	}

}
//存指针
void p_teacher_stack()
{
	stack<Teacher*> s;
	Teacher t1, t2, t3;
	t1.name = "张三";
	t1.age = 34;

	t2.name = "李四";
	t2.age = 32;

	t3.name = "王五";
	t3.age = 24;

	s.push(&t1);
	s.push(&t2);
	s.push(&t3);

	while (!(s.empty()))
	{
		s.top()->print();
		s.pop();
	}

}
void main4()
{
	//my_stack();
	//teacher_stack();
	p_teacher_stack();
	system("pause");
	return;
}